package com.multicampus.simplewiki.control.autocomplete;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class AutoCompeleteTagController extends AbstractController{
	public ArrayList<String> recommandTags;
	
	public AutoCompeleteTagController(){
		recommandTags = new ArrayList<String>();
		recommandTags.add("wiki");
		recommandTags.add("contents");
		recommandTags.add("simple");
		recommandTags.add("test");
		recommandTags.add("title");
		recommandTags.add("sample");
		recommandTags.add("tag");
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String tags = request.getParameter("tags");
		ArrayList<String> results = new ArrayList<String>();
		
		for(String item : recommandTags){
			if(item.indexOf(tags) >= 0)
				results.add(item);
		}
		
		ModelAndView mav = new ModelAndView("/autocomplete/tags");
		mav.addObject("result", results);
		return mav;
	}
}
